# #列表练习题初始
# #1
# list1 = list(range(1,6,1))
# print(list1)
# #2
# list1.append(6)
# print(list1)
# #3
# list1.pop(2)
# print(list1)
# #4
# list1[1] = 8
# print(list1)
# #5
# list1_index = list1.index(8)
# print(list1_index)
# #6
# for i in list1:
#     print(i)
# #7
# list2 = list(range(7,10,1))
# for j in list2:
#     list1.append(j)
# print(list1)
# #8
# list1.extend(list(range(10,13,1)))
# print(list1)
# #9
# print(list1[2:5:1])
# #10
# list1[2:3] = [13,14]
# print(list1)
# #列表练习题进阶
# my_list = [3,"apple",9,"banana",7,"cherry",2,"date",5,"elderberry"]
# print(my_list)
# #1
# my_list.append("fig")
# print(my_list)
# #2
# del my_list[3]
# print(my_list)
# #3
# index_7 = my_list.index(7)
# my_list[index_7] = "grape"
# print(my_list)
# #4
# print(my_list.index("cherry"))
# #5
# for i in my_list:
#     print(i)
# #6
# my_list.insert(my_list.index("cherry") + 1, "kiwi")
# print(my_list)
# #7
# print(my_list[2])
# #8
# print(my_list[-2])
# #9
# print(my_list[2:7])
# #10
# print(my_list[::-1])
# # 11
# numbers = []
# strings = []
# for item in my_list:
#     if isinstance(item, int):
#         numbers.append(item)
#     else:
#         strings.append(item)
# strings_sorted = sorted(strings)
# result = []
# str_index = 0
# for item in my_list:
#     if isinstance(item, int):
#         result.append(item)  # 数字保留原位
#     else:
#         result.append(strings_sorted[str_index])  # 按序插入字符串
#         str_index += 1
# print(result)
# #12
# num_map = {
#     1:"one",2:"two",3:"three",
#     4:"four",5:"five",6:"six",
#     7:"seven",8:"eight",9:"nine"}
# strings = []
# for b in my_list:
#     if isinstance(b, int):
#         word = num_map.get(b,b)
#         strings.append(word)
#     else:
#         strings.append(b)
# print(strings)
#列表练习题复杂
#1
sbs_list = list(range(2,101,2))
print(sbs_list)
#2
sbs_list2 = []
for x in sbs_list:
    y=x*x
    sbs_list2.append(y)
print(sbs_list2)
#3
# del  sbs_list2[sbs_list2.index(100):]
# print(sbs_list2)
#4
sbs_list3 = sbs_list[::-1]
print(sbs_list3)
#5
print(sbs_list[:10])
#6
sbs_list.extend([101,102,103])
print(sbs_list)
#7
avg = sum(sbs_list) / len(sbs_list)
print(avg)
#8
print(max(sbs_list))
print(min(sbs_list))
#9
sbs_list.append(11)
print(sbs_list.index(11))
#10
#for循环
# i = 0
# for x in sbs_list:
#     sbs_list[i] = str(x)
#     i += 1
# print(sbs_list)
#while循环
i = 0
while i < len(sbs_list):
    sbs_list[i] = (sbs_list[i])
    i = i + 1
print(sbs_list)
#11
sbs_list4 = list(map(float,sbs_list))
print(sbs_list4)
#12
sbs_list5 = []
for x in sbs_list:
    if x>50:
        sbs_list5.append(1)
print(sbs_list5.count(1))
#13
sbs_list.insert(2,99)
print(sbs_list)
#14
sbs_list.pop()
print(sbs_list)
#15
sbs_list6 = []
for x in sbs_list:
    sbs_list6.append(x*2)
print(sbs_list6)
#16
sbs_list7 = []
sbs_list8 = []
for i in sbs_list:
    if i <=50:
        sbs_list7.append(i)
    else:
        sbs_list8.append(i)
print(sbs_list7)
print(sbs_list8)
#17
# sbs_idx = []
# sbs_value = []
# for idx, value in enumerate(sbs_list):
#     sbs_idx.append(idx)
#     sbs_value.append(value)
# sbs_index8 = dict(zip(sbs_value, sbs_idx))
# print(sbs_index8)
index_dict = {value: idx for idx, value in enumerate(sbs_list)}
print(index_dict)
#18
for i,j in enumerate(sbs_list):
    print("索引{}".format(i),"元素{}".format(j))
#19
import random
random_choice = random.choice(sbs_list)
print(random_choice)
#20
with open("列表练习题.txt","w") as f:
    for i in sbs_list:
        f.write(str(i)+"\n")